package com.medusa.aps.business.modules.basic.mp.entity;

import cn.hutool.core.annotation.Alias;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.FieldStrategy;
import com.baomidou.mybatisplus.annotation.TableField;
import com.medusa.aps.business.model.BaseEntity;
import com.medusa.aps.business.model.enums.SourceEnum;
import com.medusa.aps.business.global.model.constant.RegexPools;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.math.BigDecimal;

/**
 * 供应商实体类
 *
 * @author yuxh
 * @since 2023-08-14 17:37:50
 */
@Data
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = true)
public class Supplier extends BaseEntity<Supplier> {
    /**
     * 主键
     */
    @Schema(description = "主键")
    private Long id;
    /**
     * 供应商编码
     */
    @Alias("供应商编码")
    @Schema(description = "供应商编码")
    @Size(max = 50, message = "供应商编码长度不能超过50")
    private String supplierCode;

    /**
     * 供应商名称
     */
    @Alias("供应商名称")
    @Schema(description = "供应商名称")
    @Size(max = 50, message = "供应商名称长度不能超过50")
    private String supplierName;

    /**
     * 供应商电话
     */
    @Alias("供应商电话")
    @Schema(description = "供应商电话")
    @Pattern(regexp = RegexPools.MOBILE_TEL, message = "请输入正确的电话号码，固话请用-分隔区号")
    @Size(max = 20, message = "供应商电话长度不能超过20")
    @TableField(updateStrategy = FieldStrategy.ALWAYS)
    private String supplierPhone;

    /**
     * 供应商姓名
     */
    @Alias("供应商姓名")
    @Schema(description = "供应商姓名")
    @Size(max = 50, message = "供应商姓名长度不能超过50")
    @TableField(updateStrategy = FieldStrategy.ALWAYS)
    private String supplierPerson;
    /**
     * 供应商物料id
     */
    @Schema(description = "供应商物料id")
    @TableField(exist = false)
    private Long supplierMaterialId;
    /**
     * 物料id
     */
    @Schema(description = "物料id")
    @TableField(exist = false)
    private Long materialId;

    /**
     * 物料编码
     */
    @Alias("物料编码")
    @Schema(description = "物料编码")
    @TableField(exist = false)
    @NotBlank(message = "物料编码不能为空")
    private String materialCode;
    /**
     * 物料名称
     */
    @Alias("物料名称")
    @Schema(description = "物料名称")
    @TableField(exist = false)
    private String materialName;


    /**
     * 成品率
     */
    @Alias("成品率（%）")
    @Schema(description = "成品率")
    @TableField(exist = false)
    @NotNull(message = "成品率不能为空")
    @DecimalMax(value = "100.00", message = "成品率不能大于100")
    @DecimalMin(value = "1.00", message = "成品率不能小于1")
    @Digits(integer = 3, fraction = 2, message = "成品率格式不正确")
    private BigDecimal finishedProductRate;

    /**
     * 准交率
     */
    @Alias("准交率（%）")
    @TableField(exist = false)
    @Schema(description = "准交率")
    @NotNull(message = "准交率不能为空")
    @DecimalMax(value = "100.00", message = "准交率不能大于100")
    @DecimalMin(value = "1.00", message = "准交率不能小于1")
    @Digits(integer = 3, fraction = 2, message = "准交率格式不正确")
    private BigDecimal quasiDeliveryRate;

    /**
     * 创建人
     */
    @Schema(description = "创建人")
    @TableField(fill = FieldFill.INSERT, updateStrategy = FieldStrategy.NEVER)
    private String creator;
    /**
     * 数据来源
     */
    @Schema(description = "数据来源")
    @TableField(fill = FieldFill.INSERT, updateStrategy = FieldStrategy.NEVER)
    private SourceEnum dataSource;


    /**
     * 获取主键值
     *
     * @return 主键值
     */
    @Override
    public Serializable pkVal() {
        return this.id;
    }
}

